<template>
    <form @submit.prevent="update">
      <table border="1" align="center">
        <tr>
          <td>姓名</td>
          <td><input type="text" v-model="student.name"/></td>
        </tr>
        <tr>
          <td>分数</td>
          <td><input type="text" v-model="student.score"/></td>
        </tr>
        <tr>
          <td>生日</td>
          <td><input type="text" v-model="student.birth"/></td>
        </tr>
        <tr>
          <td>班级</td>
          <td>
            <select v-model="student.cid">
              <option v-for="(c,index) in clazzList" :value="c.id" :key="index">{{c.name}}</option>
            </select>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <button>提交</button>
          </td>
        </tr>
      </table>
    </form>
</template>

<script>
    export default {
        name: "StudentTable",
      data(){
          return {
            student:{},
            clazzList:[]
          }
      },
      methods:{
        update(){
          //console.log(this.student);
          this.axios({url:"/student/update.do",method:"post",data:this.student}).then(
            (resp)=>{
              this.$router.push("/studentTable");
            }
          )
        }
      },
      created() {
          //根据id把学生对象查询出来，交给data里面的student对象
        // this.axios({url:"/student/selectOne.do",method:"get",params:{id:this.$route.query.id}}).then(
        //   (resp)=>{this.student=resp.data}
        // )
        this.student=this.$route.query.stu;
        //发出ajax请求获取到所有的班级信息,交给data里面的clazzList
        this.axios({url:"/clazz/selectAll.do",method:"get"}).then(
          (resp)=>{this.clazzList=resp.data}
        )
      }
    }
</script>

<style scoped>

</style>
